package com.gx.server.controller;

import com.gx.server.common.BaseResponse;
import com.gx.server.common.ErrorCode;
import com.gx.server.common.ResultUtils;
import com.gx.server.model.domain.ExamQuestion;
import com.gx.server.model.service.ExamCollectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Dobby
 * @version 1.0
 */
@RestController
@RequestMapping("/ExamCollect")
@Slf4j
public class ExamCollectController {

    @Autowired
    ExamCollectService examCollectService;

    @PostMapping("/add")
    public BaseResponse<String> add_collect(Long userId,int questionId){
        String s = examCollectService.add_collect(userId, questionId);
        System.out.println(s);
            return ResultUtils.success(s);

    }

    @DeleteMapping("/del")
    public BaseResponse<String> del_collect(Long userId,int questionId){
        System.out.println("---del_collect");
        boolean flag = examCollectService.del_collect(userId, questionId);
        if (flag){
            return ResultUtils.success("成功删除");
        }else {
            return ResultUtils.error(ErrorCode.PARAMS_ERROR,"删除失败");
        }
    }


    @GetMapping("/all")
    public BaseResponse<List<ExamQuestion>> all_collect(Long userId){
        List<ExamQuestion> examCollects = examCollectService.all_collect(userId);
        if (examCollects!=null){
            return ResultUtils.success(examCollects);
        }else {
            return ResultUtils.error(ErrorCode.PARAMS_ERROR,"收藏为空");
        }
    }


    @GetMapping("/CollectByUserId")
    public BaseResponse<String> CollectByUserId(Long userId,int questionId){
        int i = examCollectService.CollectByUserId(userId, questionId);
        if (i>0){
            return ResultUtils.success("已收藏");
        }else {
            return ResultUtils.error(ErrorCode.PARAMS_ERROR,"未收藏");
        }
    }


    @DeleteMapping("/del_all")
    public BaseResponse<String> del_all_collect(Long userId){
        boolean flag = examCollectService.del_all_collect(userId);
        if (flag){
            return ResultUtils.success("成功删除全部");
        }else {
            return ResultUtils.error(ErrorCode.PARAMS_ERROR,"删除失败");
        }
    }



}
